package com.liyingtao.biz;

import com.liyingtao.bean.News;
import com.liyingtao.bean.Page;
import com.liyingtao.dao.NewsMapper;
import com.liyingtao.util.SqlSessionFactoryUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class NewsService {
    SqlSession session=SqlSessionFactoryUtil.getSqlSession();
    NewsMapper newsmapper=session.getMapper(NewsMapper.class);

    public int addNews(News news){
       int flag= newsmapper.addNews(news);
       session.commit();
       return  flag;
    }

    public List<News> getNewsByPage(Page page){
        return newsmapper.getNewsByPage(page);
    }

    public int getAllPage(String keyword){
        return newsmapper.getAllPage(keyword);
    }

    public News getNewsById(int newsId){
        return newsmapper.getNewsById(newsId);
    }

    public int updateNews(News news){
        int flag=newsmapper.updateNews(news);
        session.commit();
        return  flag ;
    }

    public int deleteNews(int newsId){
        int flag=newsmapper.deleteNews(newsId);
        session.commit();
        return  flag;
    }

    public List<String> getKeywordName(String keyword){
        return newsmapper.getKeywordName(keyword);
    }
}
